package com.aqie.libcommon.app;


import com.aqie.libcommon.factory.presenter.BaseContract;

/**
 * @author aqie
 * @date 2021/2/10 20:53
 */
public abstract class PresenterActivity<Presenter extends BaseContract.Presenter> extends BaseActivity
        implements BaseContract.View<Presenter>{
    protected Presenter mPresenter;
    @Override
    protected void initBefore() {
        super.initBefore();
        initPresenter();
    }

    protected abstract Presenter initPresenter();

    @Override
    public void showError(String errMsg) {
        // 显示错误, 优先使用占位布局
        if (mPlaceHolderView != null) {
            mPlaceHolderView.triggerEmpty(errMsg);
        } else {
            BaseApplication.showToast(errMsg);
        }
    }

    @Override
    public void showLoading() {
        if (mPlaceHolderView != null) {
            mPlaceHolderView.triggerLoading();
        }
    }

    @Override
    public void setPresenter(Presenter presenter) {
        // View中赋值Presenter
        mPresenter = presenter;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (mPresenter != null)
            mPresenter.destroy();
    }
}
